home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / info / ti801.zip / TI801.TXT
Text File  |  1992-08-12  |  3KB  |  38 lines

  1.  
  2. PRODUCT  :  C++                                    NUMBER  :  801             
  3. VERSION  :  All                                                               
  4. OS  :  DOS                                                                    
  5. DATE  :  February 25, 1992                        PAGE  :  1/1                
  6.                                                                               
  7. TITLE  :  Defining and Using Arrays of Pointers to Functions                  
  8.                                                                               
  9.                                                                               
  10.                                                                               
  11.                                                                               
  12. The following demonstrates how to define and initailize an array              
  13. of pointers to functions.  In addition, calling a function whose              
  14. pointer is contained in such an array is demonstrated.                        
  15.                                                                               
  16. #include <stdio.h>                                                            
  17.                                                                               
  18. void (*p[5])();            // p is defined to be an array of                  
  19. // 5 pointers to functions taking                                             
  20. // no (void) paramaters and returning                                         
  21. // nothing (void)                                                             
  22.                                                                               
  23. void foo1(void) { printf("Hello, in function foo1\n"); }                      
  24. void foo2(void) { printf("Hello, in function foo2\n"); }                      
  25.                                                                               
  26. main()                                                                        
  27. {                                                                             
  28. p[0]=foo1;  // Assign pointer at array index 0                                
  29. // to point at function foo1.                                                 
  30. p[0]();     // Now call foo1                                                  
  31.                                                                               
  32.                                                                               
  33. p[1]=foo2;  // Assign pointer at array index 1                                
  34. // to point to function foo2.                                                 
  35. p[1]();     // Now call foo2                                                  
  36. }                                                                             
  37.                                                                               
  38.